﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace QuanLyKhachSan
{
    public partial class frmThucAnThucUong : DevExpress.XtraEditors.XtraForm
    {
        bool them = false;
        DataClassesKhachSanDataContext db = new DataClassesKhachSanDataContext();
        public frmThucAnThucUong()
        {
            InitializeComponent();
        }

        private void frmThucAnThucUong_Load(object sender, EventArgs e)
        {
            this.fillData();
            this.fillNganhHang();
        }
        private void fillData()
        {



            var doituong = from dt in db.DOI_TUONGs
                           where dt.THUC_UONG_THUC_AN_NHANH.DT_ID == dt.DT_ID
                           select dt;
            gridControlTATU.DataSource = doituong;
        }
        private void fillNganhHang()
        {
            var nganhhang = from nh in db.NGANH_HANGs select nh;
            cbNganhHang.DataSource = nganhhang;
            cbNganhHang.DisplayMember = "NH_TEN";
            cbNganhHang.ValueMember = "NH_TEN";
        }

        private void btLuu_Click(object sender, EventArgs e)
        {

            db.SubmitChanges();
            
        }

        private void gridViewTATU_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
        {
            them = true;
        }

        private void gridViewTATU_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            if (them == true )
            {
                DOI_TUONG dt = (DOI_TUONG)e.Row;
                THUC_UONG_THUC_AN_NHANH ta = new THUC_UONG_THUC_AN_NHANH();
                ta.DOI_TUONG = dt;
                db.THUC_UONG_THUC_AN_NHANHs.InsertOnSubmit(ta);
            }
        }

        private void gridViewTATU_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "")
	{
        if (e.RowHandle >= 0)
        {
            e.DisplayText =  (e.RowHandle + 1).ToString ();
        }
	} 
        }

        private void btXoa_Click(object sender, EventArgs e)
        {

        
          
            gridViewTATU.DeleteSelectedRows();

        }
    
    }
}